#include <stdio.h>

typedef unsigned char N1;
typedef unsigned long int N4;
typedef   signed long int I4;

#define MEMLEN 4096ul

static I4 mem[MEMLEN]={};

int main(int argc,char **argv)
{ N1 cc; int ii; I4 n1;
  N1 c1a,c1b,c2a,c2b;
  N4 num=0; N1 dig=0;
  N4 pos=MEMLEN;

  c1a=(N1)'0'; c2a=(N1)'A';
  c1b=c1a+9; c2b=c2a+5;
  
  while (1)
  { ii=fgetc(stdin);
    if (ii==-1) break;
    else cc=(N1)ii;
    switch (cc)
    { case '+':
        if (dig) break;
        if (pos+2>MEMLEN) break;
        n1=mem[pos++];
        mem[pos]+=n1;
        break;
      default:
        if (c1a<=cc && cc<=c1b) cc-=c1a; else
        if (c2a<=cc && cc<=c2b) cc-=c2a-10;
        else ii=-1; if (ii!=-1)
        { num=(num<<4)|cc;
          dig=1; continue;
        }
        if (dig)
        { if (pos)
            mem[--pos]=num;
          num=0; dig=0;
        }
        if (cc=='\n' && pos<MEMLEN)
        { n1=mem[pos++];
          printf("%li  0x%08lX\n",
            n1,n1); continue;
        }
    }
  }
  fflush(stdout);

  return (0);
}
